package com.itheima.thread.communication.demo03;

import java.awt.*;

public class ProducerThread implements Runnable {

    private Box box;
    public ProducerThread(Box box) {
        this.box = box;
    }

    private int count = 0;

    @Override
    public void run() {

        while (true) {

            synchronized (box) {

                if(box.isFlag()) {
                    try {
                        box.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                if(count % 2 == 0) {
                    box.setMilkType("牛奶");
                    box.setAmount("5L");
                }else {
                    box.setMilkType("羊奶");
                    box.setAmount("10L");
                }

                box.setFlag(true);

                box.notify();

            }

            count++;

        }

    }
}
